*** Settings ***
Resource          ../../CommonVars/Locations/SITFIN/LMenu.robot
Resource          ../../CommonVars/Locations/SITFIN/LLogin.robot
Library           Selenium2Library
Resource          ../../CommonVars/Locations/SITFIN/L见费出单.robot
Resource          ../../CommonVars/Locations/SITFIN/L资金缴费.robot
Library           ../../CommonLibs/SeleniumUtils/CustomSeleniumLibrary.py
Resource          ../../CommonVars/Locations/SITFIN/L见费出单到账确认.robot
Library           ../../CommonLibs/FDataFactors/FormatData.py

*** Keywords ***
登录收付系统
    [Arguments]    ${url}    ${username}    ${passwd}
    Open Browser    ${url}    headlesschrome
    Set Window Size    1600    890
    #${options}=    get_headlesschrome_options
    #${dirver}=    Create Webdriver    Chrome    chrome_options=${options}
    GO TO    ${url}
    SET SELENIUM IMPLICIT WAIT    5
    Maximize Browser Window
    input text    ${LUsername}    ${username}
    input text    ${LPassword}    ${passwd}
    click Button    ${LSubmit}

菜单管理
    Reload Page
    sleep    2
    Select Frame    ${LLeftFrame}
    ${style}=    Get Element Attribute    ${L见费出单Style}    style
    FOR    ${var}    IN RANGE    0    9999
        Run Keyword If    ''!='${style}'    run keywords    Reload Page
        ...    AND    Select Frame    ${LLeftFrame}
        ...    AND    Click Element    ${L见费出单}
        ...    ELSE    log    ${style}
        sleep    3
        ${style}=    Get Element Attribute    ${L见费出单Style}    style
        Exit For Loop If    ''=='${style}'
    END
    Click Element    ${L见费出单缴费}
    Unselect Frame

Go 见费出单
    [Arguments]    ${proposalno}
    [Documentation]    问题：
    ...    1、当收付时 当前数据不能正常的收付
    菜单管理
    Select Frame    ${LmainFrame}
    input text    ${L投保单号/批单申请号}    ${proposalno}
    Sleep    2
    click element    ${L查询}
    Sleep    3
    Select Frame    ${LQueryResultFrame}
    ${info}=    Get Element Attribute    ${L查询结果}    innerText
    run keyword if    '${info}' in '${proposalno}'    Run keywords    click element    ${L结果复选框}
    ...    AND    click element    ${L缴费登记}
    ...    ELSE    Set To Dictionary    ${proposalnolist}    ${proposalno}    无查询到记录
    # 是否存在已经缴费弹框    所选投保单号/批单申请号 \ 0021505031720210000052 处理状态为已处理或已生成交易流水号，不能进行缴费登记!
    FOR    ${var}    IN RANGE    0    2
        sleep    3
        ${alertMsg}=    Alert Should View
        run keyword if    '处理状态为已处理或已生成交易流水号，不能进行缴费登记' in '${alertMsg}'    RUN KEYWORDS    Handle Alert
        ...    AND    Set To Dictionary    ${proposalnolist}    ${proposalno}    不能进行缴费登记
        Exit for loop if    'False'not in'${alertMsg}'
    END
    电子投保
    资金缴费    ${proposalno}
    unSelect Frame
    ${hanlds}=    get window handles
    select window by handle    ${hanlds}[1]
    ${交易流水号}=    Get element attribute    ${L交易流水号}    innerText
    close window
    select window by handle    ${hanlds}[0]
    ${保单}=    Run Keyword And Continue On Failure    见费出单到账确认    ${交易流水号}    ${proposalno}
    Set To Dictionary    ${proposalnolist}    ${proposalno}    ${保单}
    [Return]    ${保单}

电子投保
    ${countdiv2}=    Get Element count    id=div2
    ${countdiv3}=    Get Element count    id=div3
    ${电子投保Style}=    run keyword if    ${countdiv2} > 0    Get Element attribute    id=div2    style
    ${强制电子投保Style}=    run keyword if    ${countdiv3} > 0    Get Element attribute    id=div3    style
    run keyword if    'display' not in '${电子投保Style}' and ${countdiv2} > 0    click element    ${L否}
    ...    ELSE IF    'display' not in '${强制电子投保Style}' and ${countdiv3} > 0    click element    ${L关闭}

资金缴费
    [Arguments]    ${proposalno}
    Sleep    2
    unselect frame
    select frame    ${LmainFrame}
    click element    ${L资金缴费}
    Set To Dictionary    ${proposalnolist}    ${proposalno}    缴费中
    Select From List By Index    ${L我司银行账号}    1
    ${num}=    Evaluate    random.randint(1000, sys.maxsize)
    #江苏付款人账户名称#其他 银行回执单
    ${len}=    Get Length    ${proposalnolist}
    ${keys}=    Get Dictionary Keys    ${proposalnolist}
    ${values}=    Get Dictionary Values    ${proposalnolist}
    # 一条数据
    FOR    ${var}    IN RANGE    0    ${len}
        run keyword if    '机构代码' in ${keys}[${var}] and '0108' in '${values}[${var}][0:4]'    input text    ${L付款人账户名称}    ${num}
        ...    ELSE IF    '机构代码' in ${keys}[${var}]    input text    ${L银行回单号}    ${num}
        exit for loop if    '机构代码' in ${keys}[${var}]
    END
    sleep    1
    click element    ${L提交复核}
    FOR    ${var}    IN RANGE    0    2
        sleep    3
        ${alertMsg}=    Alert Should View
        run keyword if    '确定提交' in '${alertMsg}'    Handle Alert
        ...    ELSE    log    True
        Exit for loop if    'False'not in'${alertMsg}'
    END

SelectWin
    [Arguments]    ${window_titles}
    ${len}=    Get Length    ${window_titles}
    FOR    ${var}    IN RANGE    ${len}
        ${title}=    Get From List    ${window_titles}    ${var}
        run keyword if    '${title}'=='undefined'    select window    title=${title}
    END

见费出单到账确认
    [Arguments]    ${交易流水号}    ${proposalno}
    ${交易流水号1}=    NumFormatStr    ${交易流水号}
    Select Frame    ${LLeftFrame}
    Click Element    ${L见费出单到账确认}
    Unselect Frame
    sleep    2
    Select Frame    ${LmainFrame}
    input text    ${L交易流水号input}    ${交易流水号1}
    Click Element    ${L查询}
    sleep    2
    Select Frame    ${LQueryResultFrame}
    ${info}=    Get Element Attribute    ${L查询结果}    innerText
    run keyword if    '${info}' in '${交易流水号1}'    Run keywords    click element    ${L结果复选框}
    ...    AND    click element    ${L见费出单到账确认BTN}
    Sleep    8
    unSelect Frame
    Select Frame    ${LmainFrame}
    ${count}=    get element count    ${L保单}
    ${titles}=    Get Element Attribute    ${L承保确认消息}    innerHTML
    run keyword if    '成功' in """${titles}"""    Set To Dictionary    ${proposalnolist}    ${proposalno}    承保确认失败
    ${保单}=    Get Element Attribute    ${L保单}    innerHTML
    ${保单1}=    NumFormatStr    ${保单}
    Should Contain    ${titles}    承保确认成功
    [Return]    ${保单1}
